/******************************************************************************
秋夜静，独坐对残灯。
啼笑非非谁识我，坐行梦梦尽缘君，何所慰消沉。
风卷雨，雨复卷侬心。
心似欲随风雨去，茫茫大海任浮沉。
无爱亦无恨。
******************************************************************************/
#ifndef _KB_RGB_INT_H_
#define _KB_RGB_INT_H_

#include <stdint.h>
#include "Effects/kbRGB_Int/kbRGB_Sin.h"
#include "Effects/kbRGB_Int/kbRGB_XY2Angle.h"
#include "Curve/hsv.h"
//#include "UGUI/ugui.h"
#include "Effects/kbRGB_Int/SimplexNoises_Int.h"
//#include "Effects/kbRGB/kbRGB.h"
#include "Effects/kbRGB_Int/kbRGB_Int_type.h"

#ifdef __cplusplus
extern "C" {
#endif

#define kbRGB_pointsSize    8

struct kbRGB_Int_Params {
    volatile uint32_t FPS;
    volatile uint16_t Speed;
    volatile uint8_t  Slider2Val;
	volatile uint8_t  reverse;
    union {
		double Progress;
        //double Time;
		struct {
			int32_t progress;
			uint32_t time;
		};
	};
    uint32_t background;
    //int frequency;
    hsv_t hsv;
	union
	{
		uint32_t UserColors[8];
		uint32_t Palette[8];
	};

    union {
		/*************************************************************************************************\
		|        cledMatrixView                                                                            |
		\*************************************************************************************************/
		struct mled_view_t mled_view;
		struct mled_view_diffusion_t mled_view_Diffusion;
		//struct {udef};
        /*************************************************************************************************\
        |        Advanced [13-1]                                                                          |
        \*************************************************************************************************/
        struct kbRGB_Int_BouncingBall_t Advanced_BouncingBall;
        struct kbRGB_Int_Bubbles_t Advanced_Bubbles;
        struct kbRGB_Int_FractalMotion_t Advanced_FractalMotion;
        int spread;// = 0;
        struct kbRGB_Int_MovingPanes_t Advanced_MovingPanes;
        struct kbRGB_Int_Rain_t Advanced_Rain;
        struct kbRGB_Int_SmoothBlink_t Advanced_SmoothBlink;
        struct kbRGB_Int_StarryNight_t Advanced_StarryNight;  // 星空
        struct {
            hsv_t hsv1;
            hsv_t hsv2;
            int radius;
        }Advanced_SwirlCircles;
        struct kbRGB_Int_Wavy_t Advanced_Wavy;
        /*************************************************************************************************\
        |        Beams [2]                                                                                |
        \*************************************************************************************************/
        struct kbRGB_Beams_t Beams;
        /*************************************************************************************************\
        |        Rainbow [9-1]                                                                            |
        \*************************************************************************************************/
        struct {
            int frequency;
            double _time;
        }Rainbow_DoubleRotatingRainbow;
        struct kbRGB_Int_NoiseMap_t Rainbow_NoiseMap;
        struct {
            int frequency;
            unsigned int shape;
        }Rainbow;
        struct kbRGB_Int_RainbowHypn_t RainbowHypn;
        /*************************************************************************************************\
        |        Random [2]                                                                               |
        \*************************************************************************************************/
        struct kbRGB_Flower Random_flowers[KB_COLS*KB_ROWS];
        struct {
            struct kbRGB_Lightning_t Lightnings[LightningsSizeMax];
            uint32_t mode;
        }Random_Lightning;
        /*************************************************************************************************\
        |        Simple [11]                                                                              |
        \*************************************************************************************************/
        struct {
            int stops;//=0;
            int horizontal;
            uint32_t old_dir;// = 0;
        }Simple;
        struct kbRGB_Mosaic_t Simple_Mosaic_tiles[KB_COLS*KB_ROWS];
        struct kbRGB_Int_MovingPoint Simple_points[kbRGB_pointsSize];
        int32_t Simple_Fill_old_progress;// = 0;
        //int   Simple_last_step;
        struct kbRGB_Int_Swap_t Simple_Swap;
        struct kbRGB_Int_Visor_t Simple_Visor;
    };
};

struct kbRGB_Int_Effect_t {
    void (*const Init)(struct kbRGB_Int_Params *const params);
    void (*const Effect)(const uint16_t cols, const uint16_t rows, const uint8_t speed, const int reverse, struct kbRGB_Int_Params *const params);
};

#define KB_RGB_PARAM_PRE         8   // 精度 8 bit

extern uint32_t tb_get_sys_time_ms(void);

extern int16_t kbRGB_Int_Init(const uint8_t index);
//extern void kbRGB_Int_Params_Init(void);
// return FPS
extern int kbRGB_Int_Effects(const uint8_t index, const uint16_t cols, const uint16_t rows, const uint32_t background, const uint8_t speed, const int reverse);
extern struct mled_view_t* kbRGB_Int_mled_view(void);
//清屏函数
extern void kbRGB_clear(void);
extern void kbRGB_pset(const int16_t x, const int16_t y, const uint32_t t);
extern uint32_t kbRGB_get_point(const int16_t x, const int16_t y);

//extern struct kbRGB_Int_Params kbrgb_Int_Params;
#define kbRGB_FPS              (kbrgb_Params.FPS)
#define kbRGB_Speed            (kbrgb_Params.Speed)
#define kbRGB_Slider2Val       (kbrgb_Params.Slider2Val)
#define kbRGB_progress         (kbrgb_Params.progress)
#define kbRGB_time             (kbrgb_Params.time)
#define kbRGB_PRE_BIT          8
#define kbRGB_PRE_MAX          255

//extern const struct kbRGB_Effect_t kbrgb_effect_int[KB_RGB_EFFECTS];
extern uint16_t kb_rand(void);
extern unsigned short kb_sqrt(unsigned long a);

#ifdef __cplusplus
}
#endif

#endif // _KB_RGB_INT_H_
